package com.application.mestory.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.application.mestory.entity.MeStory;

@Repository
public class StoryDaoImpl implements StoryDao {

	@PersistenceContext
	private EntityManager entityManager;

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	@SuppressWarnings("unchecked")
	@Transactional
	@Cache(usage=CacheConcurrencyStrategy.NONE)
	public List<MeStory> load() {
		List<MeStory> stories=  entityManager.createQuery("from MeStory").getResultList();
		return stories;
	}
	
	@Transactional
	public void save(MeStory story) {
		entityManager.merge(story);
	}

}
